{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# <center> UNSW-NB15 Dataset Visualizations Notebook <center/>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "import sys\n",
    "sys.path.append('../')\n",
    "\n",
    "import preprocessing, utils\n",
    "preprocessing.data_folder = \"../../Data/UNSW-NB15\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'Analysis': 0, 'Backdoor': 1, 'DoS': 2, 'Exploits': 3, 'Fuzzers': 4, 'Generic': 5, 'Normal': 6, 'Reconnaissance': 7, 'Shellcode': 8, 'Worms': 9}\n",
      "get_contant_featues : [DONE]\n"
     ]
    }
   ],
   "source": [
    "train,test, label_mapping = preprocessing.get_data()\n",
    "data_cols = list(train.drop([\"label\",\"attack_cat\"],axis=1).columns)\n",
    "train = preprocessing.normalize_data(train,data_cols)\n",
    "train , _ = preprocessing.preprocess(train,test,data_cols,\"Robust\",True)\n",
    "print(label_mapping)\n",
    "x_train,y_train = train.drop([\"label\",\"attack_cat\"],axis=1),train.attack_cat.values\n",
    "\n",
    "train,test = None, None\n",
    "\n",
    "data_cols = list(x_train.columns)\n",
    "\n",
    "to_drop = preprocessing.get_contant_featues(x_train,data_cols,threshold=0.99)\n",
    "print(\"get_contant_featues : [DONE]\")\n",
    "x_train.drop(to_drop, axis=1,inplace=True)\n",
    "\n",
    "data_cols = list(x_train.columns)\n",
    "\n",
    "att_ind = np.where(y_train != label_mapping[\"Normal\"])[0]\n",
    "\n",
    "\n",
    "del label_mapping[\"Normal\"] #remove Normal netwok traffic from data\n",
    "x = x_train[data_cols].values[att_ind]\n",
    "y = y_train[att_ind]\n",
    "\n",
    "\n",
    "utils.PlotPCA(2,x,y,label_mapping,save_dir=\"../unsw_pcaplots\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
